package first.niuke.simple;

/**
 * @ClassName NC101
 * @description:
 * @author: 荣燊
 * @create: 2021-04-11 17:17
 **/
public class NC101 {
    public static void main(String[] args) {
        int[] a = {0, 1, 2, 3, 5, 6, 7};
        System.out.println(solve(a));
    }

    public static int solve (int[] a) {
        // write code here
        //二分法，每个数字必须在自己的位置上
        int i = 0;
        int j = a.length-1;

        while (i<j) {
            int tmp = (i+j) / 2;
            if (tmp != a[tmp]) {
                j = tmp;
            } else {
                i = tmp+1;
            }
        }

        return i;
    }
}
